<template>
  <el-config-provider :locale="appStore.locale" :size="appStore.size" >
    <a-config-provider :locale="appStore.locale.name==='zh-cn'?locale:null" :theme="themeConfig">
      <router-view />
    </a-config-provider>
  </el-config-provider>
</template>

<script setup lang="ts">
import useSettingsStore from '@/store/modules/settings';
import { handleThemeStyle } from '@/utils/theme';
import useAppStore from '@/store/modules/app';
import { theme } from 'ant-design-vue';

import zhCN from 'ant-design-vue/es/locale/zh_CN';
import 'dayjs/locale/zh-cn';
import { SideThemeEnum } from '@/enums/SideThemeEnum';

const locale = ref(zhCN);
const appStore = useAppStore();
const settingsStore = useSettingsStore();
const themeConfig = computed(() => ({
  algorithm: settingsStore.sideTheme===SideThemeEnum.DARK ? theme.darkAlgorithm : theme.defaultAlgorithm,
  token: {
    colorPrimary: useSettingsStore().theme,
  },
}));
// Listening to page changes and dynamically changing site titles
useTitle();

const { token } = theme.useToken();
onMounted(() => {
  nextTick(() => {
    // 初始化主题样式
    handleThemeStyle(useSettingsStore().theme);
  });
});
</script>
